package com.tcse.ppmethodhandler.entity;

import lombok.Data;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * @author aozeliu
 */
@Data
public class HttpTrace {

    private String traceId;
    private String taskId;
    private String test;
    private HttpInfo httpInfo;
    private List<SpanRecord> records = new ArrayList<>();
    private Long spanId;
    private short type;
    
    
    public HttpTrace(){}

    public HttpTrace(String traceId) {
        this.traceId = traceId;
    }

    public HttpTrace(String traceId, String test, String url) {
        this.traceId = traceId;
        this.test = test;
        this.httpInfo = new HttpInfo(url);
    }

    public List<SpanRecord> getRecords() {
        return records;
    }

    public void setRecords(List<SpanRecord> records) {
        this.records = records;
    }

    public String getTest() {
        return test;
    }
    public void setTest(String test) {
        this.test = test;
    }

    public String getTraceId() {
        return traceId;
    }

    public String getTaskId() {
        return taskId;
    }

    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }

    public HttpInfo getHttpInfo() {
        return httpInfo;
    }
    public void setUrl(String url){
        httpInfo = new HttpInfo(url);
    }
    
    public short getType() {
        return type;
    }
    
    public void setType(short type) {
        this.type = type;
    }
    
    public void addRecords(SpanRecord spanRecord){
        if(spanRecord != null){
            records.add(spanRecord);
        }
    }
    
    public String toString(){
        String httpInfoString = httpInfo==null?"HttpInfo: 'null', ":httpInfo.toString();
        String recordsString = records==null?"null":records.toString();
        
        return "HttpTrace{" +
                "traceId: '" + traceId + "', " +
                "taskId: '" + taskId + "', " +
                "test: '" + test + "', " +
                "spanId: '" + spanId + "', " +
                "type: '" + type + "', " +
                httpInfoString +
                "records: '" + recordsString + "'"
                + "}";
        
    }

}
